package com.wontube.smr.remote.web;

import java.util.HashMap;
import java.util.List;

import com.wontube.core.annotation.CacheSupport;
import com.wontube.core.annotation.NoLoginSupport;
import com.wontube.core.pub.servlet.handlers.BasicHandler;
import com.wontube.smr.bo.sites.fs.Mp3SearchBO;
import com.wontube.smr.bo.sites.fs.TopMusicObtainBO;
import com.wontube.smr.bo.sites.fs.api.SimpleAPI;
import com.wontube.smr.client.model.po.TopMusic;
import com.wontube.smr.client.model.vo.AudioFiles;
import com.wontube.smr.web.client.IMp3WebHandler;


/**
 * @author yuechao
 * 
 */
@NoLoginSupport
public final class Mp3WebHandler extends BasicHandler implements IMp3WebHandler {
	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public HashMap<String, List<TopMusic>> getTopMusic() throws RuntimeException {
		return TopMusicObtainBO.getTopMusic();
	}

	@Override
	@CacheSupport
	public AudioFiles search(String query, int pageIndex) throws RuntimeException {
		try {
			return Mp3SearchBO.search(query, pageIndex);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public List<TopMusic> getBillboard() throws RuntimeException {
		return TopMusicObtainBO.getCategary("billboard");
	}

	
	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public List<TopMusic> getItunes() throws RuntimeException {
		return TopMusicObtainBO.getCategary("itunes");
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public List<TopMusic> getUK() throws RuntimeException {
		return TopMusicObtainBO.getCategary("uk");
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public List<TopMusic> getLastFm() throws RuntimeException {
		return TopMusicObtainBO.getCategary("last_fm");
	}

	@Override
	@CacheSupport
	public String getDirectLink(String link) {
		SimpleAPI api = new SimpleAPI();
		String directLink = api.getDirectLink(link);

		return directLink;
	}
}
